<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>$!{config.bargain_title} - $!config.title - Powered by ezsheng</title>
<meta name="keywords" content="$!config.keywords" />
<meta name="description" content="$!config.description" />
<meta name="generator" content="ezs 2.0" />
<meta name="author" content="www.ezsheng.com"/>
<meta name="copyright" content="ezs Inc. All Rights Reserved"/>
<link href="$!webPath/resources/layui/css/layui.css" rel="stylesheet" type="text/css"/>
</head>
<body>
    <form class="layui-form layui-form-pane"  method="post">
       <input type="hidden" name="area_id" value="$!obj.area.id"/>
       <input type="hidden" name="id" value="$!obj.id"/>
       <input type="hidden" name="bestow" value="#if($!obj&&$!obj.bestow)true #else false #end"/>
       <div class="layui-form-item">
		    <label class="layui-form-label">收货人姓名</label>
		    <div class="layui-input-block">
		       <input name="trueName" autocomplete="off" placeholder="请输入收货人姓名" class="layui-input" type="text" lay-verify="required" value="$!obj.trueName"/>
		    </div>
	   </div>
	  <div class="layui-form-item">
    	<label class="layui-form-label">收货地址</label>
	    <div class="layui-input-inline" style="width: 140px;">
	      <select  lay-verify="required" name="shengDome" lay-filter="shengDome">
	        <option value="" >请选择省</option>
	        #foreach($as in $!areas)
		        <option value="$!as.id" #if($!as.id==$!obj.area.parent.parent.id) selected="selected" #end>$!as.areaName</option>
	         #end
	      </select>
	    </div>
	    <div class="layui-input-inline" style="width: 130px;">
	      <select name="quDome" lay-verify="required" lay-filter="quDome">
	        <option value="" >请选择市</option>
	        #if($!obj)
	            #set($qus=$!areaViewTools.getAreaBypid($!obj.area.parent.parent.id))
	            #foreach($qu in $!qus)
	               <option value="$!qu.id" #if($!qu.id==$!obj.area.parent.id) selected="selected" #end>$!qu.areaName</option>
	            #end
	        #end
	      </select>
	    </div>
	    <div class="layui-input-inline" style="width:120px;">
	      <select name="xianDome" lay-verify="required" lay-filter="xianDome">
	        <option value="">请选择县/区</option>
	          #if($!obj)
	            #set($xians=$!areaViewTools.getAreaBypid($!obj.area.parent.id))
	            #foreach($xian in $!xians)
	               <option value="$!xian.id" #if($!xian.id==$!obj.area.id) selected="selected" #end>$!xian.areaName</option>
	            #end
	        #end
	      </select>
	    </div>
	    <div class="layui-input-inline" style="margin-left: 20px;width: 470px;margin-top: 10px;">
	        <textarea placeholder="请输入详情地址" class="layui-textarea" name="area_info" lay-verify="required">$!obj.area_info</textarea>
	    </div>
	    <div class="layui-form-item">
		    <label class="layui-form-label">手机号码</label>
		    <div class="layui-input-block">
		       <input name="telephone" autocomplete="off" placeholder="请输入手机号码" class="layui-input" type="text" lay-verify="required|phone" value="$!obj.telephone"/>
		    </div>
	   </div>
	   <div class="layui-form-item">
		    <label class="layui-form-label">备用号码</label>
		    <div class="layui-input-block">
		       <input name="mobile" autocomplete="off" placeholder="请输入备用号码" class="layui-input" type="text" lay-verify="phone" value="$!obj.mobile"/>
		    </div>
	   </div>
	    <div class="layui-form-item">
		    <div class="layui-input-block">
		      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
		      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
  		</div>
    </div>
    </form>
   <script src="$!webPath/resources/layui/layui.all.js" charset="utf-8"></script>
   <script type="text/javascript" charset="utf-8">
     layui.use(["form"], function(){
	   var form = layui.form;
	   var jQuery = layui.jquery;
	   form.verify({
		    phone: function(value){
		      var pattern = /^1[34578]\d{9}$/; 
		      if(!pattern.test(value)){
		        return '请输入正确的手机号码!';
		      }
		    }
		  });
	   form.on('select(shengDome)', function(data){
		      jQuery.post("$!webPath/load_area.htm",{"pid":data.value},function(data){
			     jQuery("select[name='quDome']").empty();
			     jQuery("select[name='areaid']").empty();
			     jQuery("select[name='quDome']").append("<option value=''>请选择市</option>");
			    jQuery.each(data, function(index,item){
				     jQuery("select[name='quDome']").append("<option value='"+item.id+"'>"+item.areaName+"</option>");
			    	 form.render(); 
				});
			  },"json");
		     
	  });  
	  form.on("select(quDome)",function(data){
		  jQuery.post("$!webPath/load_area.htm",{"pid":data.value},function(data){
			     jQuery("select[name='xianDome']").empty();
			     jQuery("select[name='xianDome']").append("<option value=''>请选择县/区</option>");
			    jQuery.each(data, function(index,item){
			        jQuery("select[name='xianDome']").append("<option value='"+item.id+"'>"+item.areaName+"</option>");
			    	form.render(); 
				});
			  },"json");
	  });
	  form.on("select(xianDome)",function(data){
		  jQuery("input[name='area_id']").val(data.value);
	  })
	  form.on('submit(formDemo)', function(data){
		  var index = layer.load(1, {shade: [0.1,'#fff']});
		  jQuery.ajax({
				  url:"$!webPath/cart_address_save_ajax.htm",
				  data:data.field,
				  type:"post",
				  dataType:"json",
				  success:function(reslut){
					  layer.close(index);
					  if(reslut.code =="success"){
						  parent.msgCode = "success";
						  var pindex = parent.layer.getFrameIndex(window.name);
						  parent.layer.close(pindex);
						  top.layer.alert(reslut.msg,{icon:1});
					  }else if(reslut.code =="noSession"){
						  parent.msgCode = "noSession";
						  var pindex = parent.layer.getFrameIndex(window.name);
						  parent.layer.close(pindex);
						  top.layer.alert(reslut.msg,{icon:4});
					  }else{
						  top.layer.alert(reslut.msg,{icon:2}); 
					  } 
				  }
			});
		   return false;
	  });
	})
	</script>
</body>
</html>